package com.jun.controller.user;

import com.jun.pojo.vo.R;
import com.jun.pojo.vo.SysOrderUserVo;
import com.jun.service.SysOrderUserService;
import com.jun.util.QRCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/qrcode")
public class QRCodeController {

  @Autowired
  private SysOrderUserService sysOrderUserService;

  /**
   * @param orderId : 根据orderId找到订单id
   * @return 返回Base64过的二维码图片
   */
  @GetMapping("/{orderId}")
  public R qrCode(@PathVariable("orderId") Integer orderId) {
    // Base64过的二维码图片
    String qrCode = QRCodeUtil.getBase64QRCodeOnLocal(orderId);

    // 返回的对象
    SysOrderUserVo sysOrderUserVo = sysOrderUserService.selectByOrderId(orderId);

    Map<String, Object> result = new HashMap<>(2);
    result.put("obj", sysOrderUserVo);
    result.put("qrCode", qrCode);

    return new R(result);
  }



}
